package com.jisu.controller;

import com.jisu.common.ResultVo;
import com.jisu.pojo.CarPart;
import com.jisu.service.CarPartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class CarPartController {

    @Autowired
    private CarPartService carPartService;

    //添加车件信息
    @PostMapping("/addCarPart")
    public ResultVo<CarPart> addCarPart(@RequestBody CarPart carPart) {
        return carPartService.addCarPart(carPart);
    }

    //根据传入id删除车件信息
    @DeleteMapping("/deleteCarPart")
    public ResultVo deleteCarPart(@RequestParam("ids") List<Integer> ids) {
        return carPartService.deleteCarPart(ids);
    }

    //通过id修改车件信息
    @PutMapping("/updateCarPart")
    public ResultVo<CarPart> updateCarPart(@RequestBody CarPart carPart) {
        return carPartService.updateCarPart(carPart);
    }

    //查询车部件信息，不传入默认显示所有信息，如需传入，可根据车部件id，车部件名字，车型id查询
    @GetMapping("/getCarPart")
    public ResultVo<List<CarPart>> getCarPart(@RequestBody(required = false) CarPart carPart) {
        return carPartService.getCarPart(carPart);
    }


    //根据车型id(modelId)查询车部件信息
    @GetMapping("/getCarPartByModelId")
    public ResultVo<List<CarPart>> getCarPartByModelId(@RequestParam("modelId") Integer modelId) {
        CarPart carPart = new CarPart();
        carPart.setModelId(modelId);
        return carPartService.getCarPart(carPart);
    }
}
